<template>
  <el-container>
    <el-header height="36px">
      <header-title title="验工计价" />
    </el-header>
    <!-- 项目信息 -->
    <el-main class="mainDetails" style="padding:15px 25px 0px">
      <TCollapse title="项目信息" style="width:100%;">
        <div class="content-box">
          <div style="text-align: justify;">
            <span id="parProName" style="width: 120px;">整体项目：{{ topdetailData.PARENT_PRJ_NAME }}</span>
            <span v-if="topdetailData.PARENT_ORG_NAME" id="parProCode ">-{{ topdetailData.PARENT_ORG_NAME }}</span>
            <span v-if="topdetailData.PARENT_PRJ_CODE" id="parProCode">【
              <span v-if="manageMode == '04' || manageMode == '03'" v-debounce="()=>skipPage(topdetailData.PARENT_PRJ_CODE)" style="color: #53c7f8;cursor: pointer;">{{ topdetailData.PARENT_PRJ_CODE }}</span>
              <span v-else>{{ topdetailData.PARENT_PRJ_CODE }}</span>
              】</span>
          </div>
          <div style="text-align: justify;">
            <span id="topdetailData.SUB_PRJ_NAME" style="width: 120px;">单项工程：{{ topdetailData.SUB_PRJ_NAME }}</span>
            <span v-if="topdetailData.SUB_ORG_NAME" id="subProCode">-{{ topdetailData.SUB_ORG_NAME }}</span>
            <span v-if="topdetailData.SUB_PRJ_CODE" id="subProCode">【{{ topdetailData.SUB_PRJ_CODE }}】</span>
          </div>
        </div>
      </TCollapse>
      <!-- 验工计价详情 -->
      <TCollapse title="验工计价" style="width:100%;">
        <div class="content-box">
          <div style="text-align:left;word-break:break-all;" class="marginBottom14">
            <div style="text-align:left;word-break:break-all;margin-left: 2px;">
              <div id="messBox">整体项目下列服务编码还未返回预估单：{{ coding }}</div>
            </div>
            <div style="color:red;">
              <div>&nbsp;&nbsp;&nbsp;&nbsp;预估单未返回时请确认以下操作是否已完成：</div>
              <div>&nbsp;&nbsp;&nbsp;&nbsp;（1）请与地市商合岗确认对应的服务编码是否已经采购下单。</div>
              <div>&nbsp;&nbsp;&nbsp;&nbsp;（2）如果已下单，请项目经理到商合交易系统完成收货（操作路径：我的业务/我的账户/订单管理），收货之后系统会在1小时左右推送预估单到PMS。可在订单详情页查询最新推送状态（查询路径：查看/查看订单报账）。</div>
            </div>
          </div>
          <!-- 按钮 -->
          <el-row :gutter="10" class="marginBottom14" type="flex" justify="end">
            <el-col :span="1.5">
              <el-button v-if="manageMode == '04' || manageMode == '03'" class="pms-button-primary" @click="skipPage(topdetailData.PARENT_PRJ_CODE)">查看交易预估单推送情况</el-button>
              <el-button class="pms-button-primary" @click="chargeAgainstFun()">冲销</el-button>
              <el-button class="pms-button-primary" @click="pushFun()">推送</el-button>
            </el-col>
          </el-row>
          <!-- 列表 -->
          <el-table
            ref="singleTable"
            :data="detailData"
            style="width: 100%"
            border
            :header-cell-style="{
              background: '#F5F5F5',
              color: '#333333'
            }"
            @select="select"
            @select-all="selectAll"
          >
            <el-table-column align="center" width="50" type="selection" />
            <el-table-column align="center" type="index" width="50" label="序号">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="siteId" label="站址编码" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="serviceCode" label="服务编码" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="serviceName" label="服务名称" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="formPattern" width="80" label="规格" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="supplier" width="90" label="供应商名称" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="orderCode" label="订单编码" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="contractCode" label="合同编码" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="shNum" width="80" label="商合预占数" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>

            <el-table-column align="center" prop="price" width="80" label="单价(元)" :show-overflow-tooltip="true">
              <template v-if="scope.row.serviceCode" slot-scope="scope">{{ roundingFour(scope.row.price) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="spuUnitAcc" width="80" label="物料精度" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="shMoney" width="80" label="商合预占金额(元)" :show-overflow-tooltip="true">
              <template v-if="scope.row.serviceCode" slot-scope="scope">{{ rounding( scope.row.shMoney) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="sumNum" width="80" label="绑定数量" :show-overflow-tooltip="true">
              <template v-if="scope.row.serviceCode" slot-scope="scope">{{ roundingFour(scope.row.sumNum) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="sumMoney" width="80" label="绑定金额" :show-overflow-tooltip="true">
              <template v-if="scope.row.serviceCode" slot-scope="scope">{{ rounding(scope.row.sumMoney) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="currentInspectionNum" width="80" label="付款数量" :show-overflow-tooltip="true">
              <template v-if="!scope.row.serviceCode" slot-scope="scope">{{ roundingFour(scope.row.currentInspectionNum) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="currentInspectionMoney" width="80" label="付款金额" :show-overflow-tooltip="true">
              <template v-if="!scope.row.serviceCode" slot-scope="scope">{{ rounding(scope.row.currentInspectionMoney) }}</template>
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="projectProGress" width="80" label="项目进度(%)" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="left" header-align="center" prop="payType" :formatter="payTypeDictionaries" width="80" label="付款类型" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="orderState" :formatter="orderStateDictionaries" width="80" label="订单状态" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="isPush" :formatter="isPushDictionaries" width="80" label="推送状态" :show-overflow-tooltip="true">
              <template slot="header" slot-scope="{ column }">
                <el-tooltip
                  effect="dark"
                  :content="column.label"
                  placement="top"
                >
                  <div class="header-tooltip">{{ column.label }}</div>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <!-- 弹框  -->
          <el-dialog
            v-dialogDrag
            title="验工计价调减"
            :visible.sync="dialogVisible"
            width="50%"
            modal
            class="pms-dialog"
            :before-close="handleColse"
            :close-on-click-modal="false"
            style="text-align: justify;"
          >
            <el-form ref="form" :inline="true" :model="form" class="pms-details pms-details-top" label-width="160px" size="mini">
              <el-row :gutter="24">
                <el-col :span="12">
                  <el-form-item label="付款类型">
                    <el-select v-model="form.payType" disabled style="width: 100%;" @change="onValuechangedPayType($event)">
                      <el-option label="进度款" value="PROGRESSING" />
                      <el-option label="首付款(含安全生产费)" value="FIRST" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="本期验工数量" prop="currentInspectionNum">
                    <el-input v-model="form.currentInspectionNum" disabled style="width: 100%;" @change="onValuechanged1($event)" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="本期验工金额(元)" class="clearfix search-flex-box pms-queryShow">
                    <el-input v-model="form.currentInspectionMoney" disabled style="width: 100%;" @change="onValuechanged($event)" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div class="formBott">
              <el-button class="pms-button-primary" type="primary" @click="newSave()">确定并推送商合</el-button>
              <el-button class="pms-button-primary" @click="close()">关闭</el-button>
            </div>
          </el-dialog>
        </div>
      </TCollapse>
    </el-main>
  </el-container>
</template>

<script>
import {
  queryInsValDetails, getChilAndParPrjInfo, getServiceReceInspection, getAccInfo, getMaterialInfo, updateInspectionValuOverallPro, inspectionValuationPush, getShopTokenAndUrl
} from '@/api/checkoutValuation'
import HeaderTitle from '@/components/basic/HeaderTitle'
import TCollapse from '@/components/basic/TCollapse.vue'
import $ from 'jquery'

    export default {
        name: 'CheckoutValuationOperateAdjust',
        components: {
        HeaderTitle,
        TCollapse
        },
        props: {
            urlForm: {
                type: Object,
                default: () => ({})
            }
        },
        data() {
            return {
                manageMode: '', // *** 管理模式(传过来的)
                prjId: '',
                activeNames: ['1', '2'], // 面板默认打开
                detailData: [], // 初始化数据
                topdetailData: [], // 初始化数据
                coding: [], // 初始化数据
                ifCurrentDeductionMoney: false, //  默认不展示扣罚金额
                yuGuDanArr: [], // 复选框存放的数据
                yanGongArr: [],
                childNodeArr: [],
                form: {
                    payType: 'FIRST', // 付款类型
                    currentInspectionNum: '', // 本期验工数量
                    currentInspectionMoney: '' // 本期验工计价金额
                },
                newOldProject: '', // 0是新项目, 1是老项目
                // 公共数据
                dialogVisible: false,
                signVal: false,
                firstNumVal: 0,
                firstMoney: 0,
                progressingNum: 0,
                progressingMoney: 0,
                firstDataId: 0,
                progressingDataId: 0
            }
        },
        created() {
            this.manageMode = this.urlForm.manageMode
            this.prjId = this.urlForm.prjId
            this.newOldProject = this.urlForm.newOldProject
            this.listData()
            this.topListData()
            // 公共的查询哪些服务编码没有返回预估单
            getServiceReceInspection({ prjId: this.prjId }).then(res => {
                if (res.code === '200' && res.data.length > 0) {
                    res.data.map((v) => {
                        this.coding.push(v)
                    })
                    this.coding = this.coding.join(',') + '。'
                } 
                 if (res.data.length === 0) {
                    this.coding = '无。'
                }
            })
        },
        methods: {
            async listData() {
                const { code, data } = await queryInsValDetails({ prjId: this.prjId, flag: '1' })
                if (code === '200') {
                    this.detailData = data
                }
            },
            async topListData() {
                const { code, data } = await getChilAndParPrjInfo({ subPrjId: this.prjId })
                if (code === '200') {
                    if (data) {
                        this.topdetailData = data
                    }
                }
            },
            // 关闭
            handleColse() {
                this.close()
            },
            close() {
                this.form = {
                    payType: 'FIRST', // 付款类型
                    currentInspectionNum: '', // 本期验工数量
                    currentInspectionMoney: '' // 本期验工计价金额
                }
                this.dialogVisible = false
            },
            // 补0
            rounding(value) {
                return Number(value).toFixed(2)
            },
            roundingFour(value) {
                return Number(value).toFixed(4)
            },
            // 推送状态字典转换
            isPushDictionaries(row) {
                switch (row.isPush) {
                    case '0':
                    return '未推送'
                    case '1':
                    return '已推送'
                    case '2':
                    return '推送超时'
                    case '3':
                    return '部分推送'
                    default:
                    break
                }
            },
            // 付款类型字典转换
            payTypeDictionaries(row) {
                switch (row.payType) {
                    case 'FIRST':
                    return '首付款（含安全生产费）'
                    case 'PROGRESSING':
                    return '进度款'
                    case 'LOSS':
                    return '损失款'
                    default:
                    break
                }
            },
            // 订单状态字典转换
            orderStateDictionaries(row) {
                switch (row.orderState) {
                    case '1':
                    return '有效'
                    case '0':
                    return '无效'
                    case '-1':
                    return '冻结'
                    default:
                    break
                }
            },
            select(selection) {
                this.yanGongArr = selection
                if (selection.length === 1) {
                    this.detailData.map(v => {
                        if (v.vid === selection[0].pid) {
                            this.yuGuDanArr.push(v)
                        }
                    })
                    this.detailData.map(v => {
                        if (selection[0].vid === v.pid) {
                            this.childNodeArr.push(v)
                        }
                    })
                } else {
                    this.yuGuDanArr = []
                    this.childNodeArr = []
                }
            },
            selectAll(selection) {
                console.log(selection, '全选')
            },
            async chargeAgainstFunrepairOne() {
              if (this.newOldProject === '0') {
                    this.$message({
                        message: '该预估单首付款无需冲销！',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
            },
            async chargeAgainstFunrepairTwo(getAccInfos) {
              if (getAccInfos.code === '200') {
                    if (getAccInfos.data === '1') {
                        this.$message({
                            message: '该项目已经过完工审核节点，请到物资服务绑定下操作！',
                            type: 'warning'
                        })
                        return Promise.reject()
                    }
                }
            },
            async chargeAgainstFunrepairThree() {
              if (this.yanGongArr.length > 1 || this.yanGongArr.length < 1) {
                    this.$message({
                        message: '当前仅支持选择一条预估单来发起冲销操作！',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
                if (this.yanGongArr.length > 0 && this.yanGongArr[0].pid !== '0') {
                    this.$message({
                        message: '当前仅支持选择一条预估单来发起冲销操作！',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
            },
            async chargeAgainstFunrepairFour() {
              if (this.yanGongArr[0].pid === '0' && this.yanGongArr[0].orderState === '1' && this.yanGongArr[0].ifAdd === '1') {
                    //   console.log('判断选择的是 预估单') 选择预估单时候执行
                } else {
                    if (this.yanGongArr[0].payType === 'FIRST') {
                         this.$message({
                            message: '支持对当前预估单发起首付款冲销操作',
                            type: 'warning'
                        })
                    }
                    if (this.yanGongArr[0].payType === 'PROGRESSING') {
                        this.$message({
                            message: '项目需处于物资服务绑定节点才可解绑操作！',
                            type: 'warning'
                        })
                    }
                    return Promise.reject()
                }
            },
            async chargeAgainstFunrepairFive(result) {
              if (result === '2') {
                this.$message({
                  message: '请将推送超时的验工计价重新推送后再调减！',
                  type: 'warning'
                })
                return Promise.reject()
              }
            },
            async chargeAgainstFunrepairSix(sign) {
              let backsign = sign
              if (this.childNodeArr[i].projectProGress === '100' && this.childNodeArr[i].payType === 'PROGRESSING') {
                backsign = true
              }
              return backsign
            },
            async chargeAgainstFunrepairSeven(flag2) {
              let backflag2 = flag2
              if (this.childNodeArr[i].payType === 'FIRST' && this.childNodeArr[i].currentInspectionMoney > 0) {
                backflag2 = true
              }
              return backflag2
            },
            async chargeAgainstFunrepairEight(flag2) {
              if (!flag2) {
                this.$message({
                  // message: '该预估单预付款无需冲销！', // 原代码
                  message: '该预估单的首付款无需冲销！', // 需确定
                  type: 'warning'
                })
                return Promise.reject()
              }
            },
            // 首付款冲销
            async chargeAgainstFun() {
                await this.chargeAgainstFunrepairOne()
                var flag = false
                const getAccInfos = await getAccInfo({ prjId: this.prjId })
                await this.chargeAgainstFunrepairTwo(getAccInfos)
                // if (flag) {
                //     return
                // }
                await this.chargeAgainstFunrepairThree()
                await this.chargeAgainstFunrepairFour()
                // 校验是否可以冲销
                var sign = false
                var firstNum = 0
                var flag2 = false
                for (var i = 0; i < this.childNodeArr.length; i++) {
                    await this.chargeAgainstFunrepairFive(this.childNodeArr[i].isPush)
                    sign = await this.chargeAgainstFunrepairSix(sign)
                    if (this.childNodeArr[i].payType === 'FIRST') {
                        this.firstDataId = this.childNodeArr[i].vid
                        firstNum = this.childNodeArr[i].currentInspectionNum
                        this.firstMoney = this.childNodeArr[i].currentInspectionMoney
                    } 
                     if (this.childNodeArr[i].payType === 'PROGRESSING') {
                        this.progressingDataId = this.childNodeArr[i].VID
                        this.progressingNum = this.childNodeArr[i].currentInspectionNum
                        this.progressingMoney = this.childNodeArr[i].currentInspectionMoney
                    }
                    flag2 = await this.chargeAgainstFunrepairSeven(flag2)
                }
                await this.chargeAgainstFunrepairEight(flag2)
                // 可以打开Form
                this.dialogVisible = true
                if (firstNum === '0') {
                    this.form.currentInspectionNum = '0'
                } else {
                    this.form.currentInspectionNum = (-firstNum)
                }
                this.form.currentInspectionMoney = (-this.firstMoney)
                this.signVal = sign
                this.firstNumVal = firstNum
            },
            async newSaverepairOne(epcServiceType, currentInspectionNum){
              var r = /^(?!0\d)\d*$/
                if (epcServiceType === '1' && !r.test(Math.abs(currentInspectionNum))) {
                    this.$message({
                        message: '该服务编码属于微站EPC总包服务编码,验工计价数量只能填写整数，请修改！',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
                if (epcServiceType === '2' && !r.test(Math.abs(currentInspectionNum))) {
                    this.$message({
                        message: '该服务编码属于微站施工总包服务编码,验工计价数量只能填写整数，请修改',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
                if (epcServiceType === '3' && !r.test(Math.abs(currentInspectionNum))) {
                    this.$message({
                        message: '该服务编码属于新疆机房总承包服务编码,验工计价数量只能填写整数，请修改！',
                        type: 'warning'
                    })
                    return Promise.reject()
                }
            },
            async newSaverepairTwo(currentInspectionNum, currentInspectionMoney, sumNum, shNum){
              if (this.firstNumVal !== '0') {
                    var Money = Number(currentInspectionNum) * Number(this.yanGongArr[0].price)
                        Money = this.farmatMoney(Money)
                    if ((((Money - 10) > currentInspectionMoney) || ((Money + 10) < currentInspectionMoney)) && sumNum !== shNum && sumNum !== 0) {
                        this.$message({
                            message: '调整区间为系统自动计算金额上下浮动' + this.floataMountMax + '元',
                            type: 'warning'
                        })
                        return Promise.reject()
                    }
                }
            },
            async newSaverepairThree(currentInspectionNum, currentInspectionMoney){
              if (currentInspectionNum < 0 || currentInspectionMoney < 0) {
                this.$message({
                  message: '调减数量金额应大于等于当前数量金额，请修改！',
                  type: 'warning'
                })
                    return Promise.reject()
                }
            },
            // 保存
            async newSave() {
                var pId = this.yanGongArr[0].vid
                var prjId = this.yanGongArr[0].prjId
                var subPrjId = this.yanGongArr[0].subPrjId
                var serviceCode = this.yanGongArr[0].serviceCode
                var siteId = this.yanGongArr[0].siteId
                var currentInspectionMoney = this.form.currentInspectionMoney
                var currentInspectionNum = this.form.currentInspectionNum
                var sumMoney = this.yanGongArr[0].sumMoney
                var sumNum = this.yanGongArr[0].sumNum
                var shNum = this.yanGongArr[0].shNum
                /** 三包服务编码只能填写整数
                 微站EPC总包服务编码规则：PMS服务编码以90050111开头，但不含9005011109开头服务编码；
                 微站施工总包服务编码规则：PMS服务编码以90050110开头，但不含9005011009开头服务编码；
                 新疆机房总承包服务编码规则：9001011008、9002010802、9003010202、9005011010开头的；
                 */
                var epcServiceType = ''
                const object = {
                    materialCode: serviceCode
                }
                const getMaterialInfos = await getMaterialInfo(object)

                if (getMaterialInfos.code === '200') {
                    epcServiceType = getMaterialInfos.data.epcServiceType
                }
                // var r = /^[1-9]\d*|0$/ // 正整数+0
               
                await this.newSaverepairOne(epcServiceType, currentInspectionNum)
                await this.newSaverepairTwo(currentInspectionNum, currentInspectionMoney, sumNum, shNum)
                 currentInspectionNum = this.currentNum() // 调减后验工计价数量
                 currentInspectionMoney = this.currentMoney() // 调减后验工计价金额
                await this.newSaverepairThree(currentInspectionNum, currentInspectionMoney)
                var taxrate = this.yanGongArr[0].taxrate
                var inspectionTax = Number(currentInspectionMoney) * Number(taxrate) // 验工计价税额 = 本期验工金额*税率
                    inspectionTax = this.farmatMoney(inspectionTax)
                var inspectionTaxAmount = this.farmatMoney(Number(currentInspectionMoney) + Number(inspectionTax)) // 含税验工计价总金额 = 本期验工金额 + 验工计价税额
                var orderDetailId = this.yanGongArr[0].orderDetailId
                var purchaseMode = this.yanGongArr[0].purchaseMode
                var payType = this.childNodeArr[0].payType
                var reduceNum = this.form.currentInspectionNum
                var reduceMoney = this.form.currentInspectionMoney
                var parentValId = this.yanGongArr[0].parentValId
                var vId = 0
                if (payType === 'FIRST') {
                    vId = this.firstDataId
                } 
                 if (payType === 'PROGRESSING') {
                    vId = this.progressingDataId
                }
                var data = { vId: vId, parentValId: parentValId, pId: pId, prjId: prjId, subPrjId: subPrjId, onlyBe1Flag: '', siteId: siteId,
						serviceCode: serviceCode, reduceNum: reduceNum, reduceMoney: reduceMoney,
						currentInspectionNum: currentInspectionNum, currentInspectionMoney: currentInspectionMoney,
						sumMoney: sumMoney, sumNum: sumNum, inspectionTax: inspectionTax,
						inspectionTaxAmount: inspectionTaxAmount, orderDetailId: orderDetailId, purchaseMode: purchaseMode,
						payType: payType, flag: '1'
						}
              const updateInspectionValuOverallPros = await updateInspectionValuOverallPro(data)
              if (updateInspectionValuOverallPros.code === '200') {
                  this.$message({
                      message: updateInspectionValuOverallPros.message,
                      type: 'success'
                  })
                  this.listData()
                  this.close()
              }
            },
            // 推送商合
            async pushFun() {
                if (this.newOldProject === '0') {
                    this.$message({
                        message: '当前预估单首付款无需推送商合！',
                        type: 'warning'
                    })
                    return
                }
                if (this.yanGongArr.length !== 1) {
                    this.$message({
                        message: '请选择一条未推送或推送超时的验工计价结果进行推送操作',
                        type: 'warning'
                    })
                    return
                }
                if (this.yanGongArr.length > 0 && this.yanGongArr[0].pid === '0') {
                    this.$message({
                        message: '请选择一条未推送或推送超时的验工计价结果进行推送操作',
                        type: 'warning'
                    })
                    return
                }
                if (this.yanGongArr[0].isPush === '1') {
                    this.$message({
                            message: '该条验工计价信息已推送商合，因此不能推送！',
                            type: 'warning'
                        })
                    return
                }
                if (this.yanGongArr[0].isPush === '2' && this.yuGuDanArr[0].orderState === '1' && this.yanGongArr[0].payType === 'FIRST' && this.yanGongArr[0].orderState === '1') {
                    // console.log('可执行')
                } else {
                    this.$message({
                            message: '仅支持对付款类型为首付款含安全生成费的有效验工计价结果且推送商合时超时发起推送操作!',
                            type: 'warning'
                        })
                    return
                }
                const gtIspectionVal = await inspectionValuationPush({ valuationDetailId: this.yanGongArr[0].vid })
                if (gtIspectionVal.code === '200') {
                    this.$message({
                        message: gtIspectionVal.message,
                        type: 'success'
                    })
                    this.listData()
                }
            },
            // 计算调减后验工计价数量
            currentNum() {
                var payType = this.form.payType
                var num = ''
                console.log(this.firstNumVal, this.progressingNum, 'num1111')
                if (this.firstNumVal === '0') {
                    return 0
                } 
                 if (this.firstNumVal !== '0') {
                    if (payType === 'FIRST') {
                        num = this.firstNumVal
                    } 
                     if (payType === 'PROGRESSING') {
                        num = this.progressingNum
                    }
                    var currentInspectionNum = this.form.currentInspectionNum
                    return this.farmatNum(num) + this.farmatNum(currentInspectionNum)
                }
            },
            // 计算调减后验工计价金额
            currentMoney() {
                var payType = this.form.payType
                var money = ''
                if (payType === 'FIRST') {
                    money = this.firstMoney
                } 
                 if (payType === 'PROGRESSING') {
                    money = this.progressingMoney
                }
                var currentInspectionMoney = this.form.currentInspectionMoney
                return this.farmatNum(money) + this.farmatNum(currentInspectionMoney)
            },
            farmatNum(Num) { // 四舍五入保留4位小数
                    var pum = 0
                    if (Num < 0) {
                        pum = -Num
                    } else {
                        pum = Num
                    }
                    var value = Math.round(Number(pum) * Math.pow(10, 4)) / Math.pow(10, 4)
                    if (Num < 0) {
                        return -value
                    } else {
                        return value
                    }
            },
            farmatMoney(money) { // 四舍五入保留2位小数
                    var pum = 0
                    if (money < 0) {
                        pum = -money
                    } else {
                        pum = money
                    }
                    var value = Math.round(pum * Math.pow(10, 2)) / Math.pow(10, 2)
                    if (money < 0) {
                        return -value
                    } else {
                        return value
                    }
            },
            // 项目编码跳转新页面
            async skipPage(subPrjCode) {
                const res = await getShopTokenAndUrl({ sysCode: 'CHNTBP', prjCode: subPrjCode })
                  if (+res.code === 200) {
                      const data = res.data
                      const toUrl = `${data.assetsResource.transactionUrl}eshop/pending/universal/sso.do?url=/v2/stage/front/index.html#/pmsEstimate?projectCode=${data.prjCode}&projectType=${data.manageMode}`
                      const params = {}
                      params.token = data.assetsResource.token
                      params.acctId = data.assetsResource.acctId
                      params.userName = data.assetsResource.userId
                      const newWin = window.open()
                      const form = $("<form method='post'></form>")
                      form.attr({ action: toUrl })
                      $.each(params, function(key, value) {
                          const input = $("<input type='hidden' >")
                          input.attr({ name: key })
                          input.val(value)
                          form.append(input)
                      })
                      form.appendTo(newWin.document.body)
                      form.submit()
                  }
            }
        }
    }
</script>

<style>
    .content-box {
        width: 100%;
        border-radius: 3px;
        font-size: 12px;
        font-weight: 400;
        line-height: 25px;
    }

    .formBott{
        text-align: center;
        margin-top: 30px;
    }
    .header-tooltip {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #messBox {
      word-break: break-all;
    }
</style>
